﻿
@{
    ViewData["Title"] = "CustomerUpdateView";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="~/libs/layui-v2.9.17/layui/css/layui.css" rel="stylesheet" />
    <script src="~/libs/layui-v2.9.17/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>


</head>
<body>
    <form class="layui-form" action="" onsubmit="return false">
        <div class="layui-form-item">
            <label class="layui-form-label">客户编码</label>
            <div class="layui-input-block">
                <input type="text" id="clientCode" name="clientCode" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户编码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">客户名称</label>
                <div class="layui-input-block">
                    <input type="text" id="clientName" name="clientName" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户名称" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户简称</label>
            <div class="layui-input-block">
                <input type="text" id="clientNick" name="clientNick" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">客户类型</label>
                <div class="layui-input-block">
                    <input type="text" id="clientType" name="clientType" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户名称" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">客户电话</label>
            <div class="layui-input-block">
                <input type="text" id="tel" name="tel" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-block">
                <input type="text" id="contact1" name="contact1" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">联系人-电话</label>
            <div class="layui-input-block">
                <input type="text" id="contact1Tel" name="contact1Tel" lay-verify="required" placeholder="请输入" autocomplete="off" lay-reqtext="请填写客户名称" class="layui-input">
            </div>
        </div>
        <input type="hidden" id="id" name="id" />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    @* <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script> *@
    <script type="text/javascript">
        layui.use(['form', 'jquery', 'layer'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            var layer = layui.layer;
            form.render();
            var meaid = window.location.search.substring(4);
            $.ajax({
                url: '/SuJiaHao/GetCustomers?id=' + meaid,
                type: 'get',
                data: $('#form').serialize(),
                success: function (res) {
                    console.log(res)
                    $('#clientCode').val(res.data.clientCode);
                    $('#clientName').val(res.data.clientName);
                    $('#clientNick').val(res.data.clientNick);
                    $('#clientType').val(res.data.clientType);
                    $('#tel').val(res.data.tel);
                    $('#contact1').val(res.data.contact1);
                    $('#contact1Tel').val(res.data.contact1Tel);
                    $('#id').val(meaid);
                    // 监听提交
                    form.on('submit(demo1)', function (data) {
                        console.log(data);
                        $.ajax({
                            url: "/SuJiaHao/UpdateCustomer",
                            type: "get",
                            async: true,
                            data: data.field,
                            contentType: "application/json",
                            success: res => {
                                console.log(res);
                                if (res.data == 1) {
                                    var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                                    parent.layer.close(index); // 再执行关闭
                                }
                                else if (res.data == 100) {
                                    layer.msg("单位编码或名称已存在")
                                }
                                else {
                                    layer.msg("修改失败")
                                }
                            }
                        });
                    });
                }

            });
        });
    </script>
</body>
</html>

